Skip to content

Fix dev env port resolution and improve multi-worktree support#2025

Merged
kodiakhq[bot] merged 2 commits intomainfrom
warren/fix-otel-dev-env-port-resolution
Apr 1, 2026
Merged

Fix dev env port resolution and improve multi-worktree support#2025
kodiakhq[bot] merged 2 commits intomainfrom
warren/fix-otel-dev-env-port-resolution

Conversation

@wrn14897
Copy link
Copy Markdown
Member

@wrn14897 wrn14897 commented Apr 1, 2026

Summary

  • Fix dev environment port isolation so OTel collector, MongoDB, and ClickHouse resolve to the correct worktree-specific ports
  • Add slot-specific session cookies so multiple worktrees on localhost don't interfere with each other's login sessions
  • Share NX build cache across worktrees for faster builds
  • Add worktrunk project config for automated worktree lifecycle management

Changes

Port resolution fix

Root .env: Replace self-referential HDX_DEV_* vars (e.g. HDX_DEV_OTEL_HTTP_PORT=${HDX_DEV_OTEL_HTTP_PORT:-4318}) with plain default values. The ${VAR:-default} syntax caused dotenv-expand infinite recursion, preventing dev-env.sh port overrides from taking effect.

packages/api/.env.development: Remove redundant self-referential port declarations and :-default fallbacks from ${HDX_DEV_*} references. Ports now come exclusively from dev-env.sh exports or root .env defaults.

packages/app/.env.development: Set HYPERDX_API_KEY to super-secure-ingestion-api-key (matching the API/collector) instead of a placeholder. Remove self-referential port declarations.

packages/app/src/config.ts: Add process.env.OTEL_EXPORTER_OTLP_ENDPOINT as fallback for HDX_COLLECTOR_URL so the browser OTel SDK picks up the correct collector endpoint.

Session cookie isolation

packages/api/src/api-app.ts: Use connect.sid.<slot> as the session cookie name in dev mode so multiple worktrees on localhost maintain independent sessions. Guarded behind config.IS_DEV && process.env.HDX_DEV_SLOT — production uses the default connect.sid.

Shared NX build cache

scripts/dev-env.sh: Set NX_CACHE_DIRECTORY=~/.config/hyperdx/nx-cache so all worktrees share a single content-hash-based build cache. Unchanged packages get cache hits regardless of worktree; changed packages rebuild correctly.

Worktrunk project config

.config/wt.toml: New project config for worktrunk (wt) worktree lifecycle hooks:

  • pre-start: Symlink node_modules/ from primary worktree (instant, no copy)
  • post-start: Copy .env.local from primary worktree
  • post-remove: Tear down Docker stacks (dev-down, dev-int-down, dev-e2e-down) for the removed worktree's slot

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

⚠️ No Changeset found

Latest commit: 8d63289

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperdx-oss Ready Ready Preview, Comment Apr 1, 2026 8:48pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

PR Review

  • ⚠️ packages/app/src/config.ts line 19: process.env.OTEL_EXPORTER_OTLP_ENDPOINT (no NEXT_PUBLIC_ prefix) is not accessible in the browser bundle in Next.js — it's server-side only. If HDX_COLLECTOR_URL is used in client-side OTel SDK initialization, this fallback will silently resolve to undefined and fall through to 'http://localhost:4318'. Verify whether HDX_COLLECTOR_URL is only used in instrumentation.ts or server-side code; if it's also used in browser code, use NEXT_PUBLIC_ prefix instead.

  • ⚠️ packages/api/.env.development: Removing :-default fallbacks (e.g., ${HDX_DEV_MONGO_PORT:-27017}${HDX_DEV_MONGO_PORT}) means if the API is started without dev-env.sh and without the root .env being loaded, MONGO_URI and other connection strings will have empty ports (e.g., mongodb://localhost:/hyperdx). Confirm that root .env is reliably loaded in all dev startup paths, or document the requirement to run via dev-env.sh.

✅ The core fixes (self-referential ${VAR:-default} → plain values in root .env, slot-specific session cookies, NX cache sharing) are correct and well-implemented. No security or production issues found.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

E2E Test Results

All tests passed • 126 passed • 3 skipped • 1066s

Status Count
✅ Passed 126
❌ Failed 0
⚠️ Flaky 2
⏭️ Skipped 3

Tests ran across 4 shards in parallel.

View full report →

const sess: session.SessionOptions & { cookie: session.CookieOptions } = {
// Use a slot-specific cookie name in dev so multiple worktrees on localhost
// don't overwrite each other's session cookies.
...(config.IS_DEV && process.env.HDX_DEV_SLOT
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid cookie session conflicts on localhost

Fix OTel collector endpoint resolution and add multi-worktree improvements:

- Fix dotenv-expand infinite recursion from self-referential ${VAR:-default}
  patterns in .env files that prevented port isolation from working
- Fix HDX_COLLECTOR_URL fallback for browser-side OTel telemetry
- Set correct HYPERDX_API_KEY in app .env.development
- Add slot-specific session cookie names (connect.sid.<slot>) so multiple
  worktrees on localhost don't overwrite each other's sessions
- Share NX build cache across worktrees via NX_CACHE_DIRECTORY
- Add worktrunk project config (.config/wt.toml) for worktree lifecycle
  hooks: symlink node_modules, copy .env.local, clean up Docker on remove
@kodiakhq kodiakhq bot merged commit dea1b66 into main Apr 1, 2026
15 of 16 checks passed
@kodiakhq kodiakhq bot deleted the warren/fix-otel-dev-env-port-resolution branch April 1, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants